package cn.xiaosiyuan.util.io.FileIO;

import cn.hutool.core.io.file.FileReader;
import cn.hutool.core.io.file.FileWriter;
import cn.hutool.core.util.CharsetUtil;

import java.io.File;

public class FileUtil {

    public static File get(String path) {
        return (cn.hutool.core.io.FileUtil.exist(path)) ? new File(path) : cn.hutool.core.io.FileUtil.newFile(path);
    }

    public static File create(String path) {
        return get(path);
    }

    public static String read(String path) {
        File file = get(path);
        FileReader fileReader = FileReader.create(file);
        return fileReader.readString();
    }

    public static void write(String path,String content) {
        File file = get(path);
        FileWriter fileWriter = FileWriter.create(file, CharsetUtil.CHARSET_UTF_8);
        fileWriter.write(content);
    }


}
